/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.sigodonto.model.dao;

import br.com.sigodonto.model.entity.Atendimento;
import br.com.sigodonto.model.entity.Dentista;
import br.com.sigodonto.model.entity.Paciente;
import br.com.sigodonto.model.entity.Tratamento;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Query;

/**
 *
 * @author Fidelis
 */
public class TratamentoDao extends DaoGenerico implements Serializable{

    public TratamentoDao() {
        super();
    }
    
    public List<Atendimento> atendimentosPorData(Date dataAtendimento){
        List<Atendimento> lista = null;
        this.getEntityManager().getTransaction().begin();

        try{
            Query q = this.getEntityManager().createQuery("SELECT a FROM Atendimento a WHERE a.dataAtendimento = :dataa");
            q.setParameter("dataa", dataAtendimento);
            lista = (List<Atendimento>) q.getResultList();
            this.getEntityManager().getTransaction().commit();
        } catch (Exception ex){
            ex.printStackTrace();
            this.getEntityManager().getTransaction().rollback();
        }
        return lista;
    }
    
    public List<Tratamento> tratamentoPorDentista(Dentista dentista){
        List<Tratamento> lista = null;
        this.getEntityManager().getTransaction().begin();

        try{
            Query q = this.getEntityManager().createQuery("SELECT t FROM Tratamento t WHERE t.dentista = :dentista");
            q.setParameter("dentista", dentista);
            lista = (List<Tratamento>) q.getResultList();
            this.getEntityManager().getTransaction().commit();
        } catch (Exception ex){
            ex.printStackTrace();
            this.getEntityManager().getTransaction().rollback();
        }
        return lista;
    }
     
    
    public List<Tratamento> tratamentoAndamentoPorPaciente(Paciente paciente){
        List<Tratamento> lista = null;
        this.getEntityManager().getTransaction().begin();

        try{
            Query q = this.getEntityManager().createQuery("SELECT t FROM Tratamento t WHERE t.paciente = :paciente AND t.status = 'ANDAMENTO'");
            q.setParameter("paciente", paciente);
            lista = (List<Tratamento>) q.getResultList();
            this.getEntityManager().getTransaction().commit();
        } catch (Exception ex){
            ex.printStackTrace();
            this.getEntityManager().getTransaction().rollback();
        }
        return lista;
    }
    
    
}
